package com.lgt_enterprise_android.base;

import android.app.Application;
import android.os.Build;

import com.lgt_enterprise_android.Constant;
import com.lgt_enterprise_android.utils.LogX;
import com.lgt_enterprise_android.utils.PrefUtils;
import com.tencent.bugly.crashreport.CrashReport;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class MyApp extends Application {

    private static MyApp instance;


    @Override
    public void onCreate() {
        instance=this;
        super.onCreate();

        CrashReport.initCrashReport(getApplicationContext(), "f5be758eb2", false);

        Constant.token=PrefUtils.getSharedPrefString(this,PrefUtils.TOKEN);




        LogX.d("cccccc",Constant.token);

        if(Build.VERSION.SDK_INT>=28){
            closeAndroidPDialog();
        }
    }


    public static MyApp getInstance() {
        return instance;
    }


    /**
     * 解决androidP 第一次打开程序出现莫名弹窗
     * 弹窗内容“detected problems with api ”
     */
    private void closeAndroidPDialog(){
        try {
            Class aClass = Class.forName("android.content.pm.PackageParser$Package");
            Constructor declaredConstructor = aClass.getDeclaredConstructor(String.class);
            declaredConstructor.setAccessible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            Class cls = Class.forName("android.app.ActivityThread");
            Method declaredMethod = cls.getDeclaredMethod("currentActivityThread");
            declaredMethod.setAccessible(true);
            Object activityThread = declaredMethod.invoke(null);
            Field mHiddenApiWarningShown = cls.getDeclaredField("mHiddenApiWarningShown");
            mHiddenApiWarningShown.setAccessible(true);
            mHiddenApiWarningShown.setBoolean(activityThread, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
